package com.sumi.test.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.sumi.test.dao.OtherListMapper;
import com.sumi.test.entity.OtherList;

@Service
public class OtherServiceImpl implements OtherServiceI {

	@Autowired
	private OtherListMapper otherListMapper;

	@Override
	public String getOterList() {
		Set<String> set = new HashSet<String>();
		List<OtherList> list = otherListMapper.selectAll();
		List<OtherList> jsonList = new ArrayList<OtherList>();
		for (OtherList other : list) {
			String title = other.getDes();
			if (set.contains(title)) {
				continue;
			} else {
				List<OtherList> t_list = new ArrayList<OtherList>();
				for (OtherList data : list) {
					if (title.equals(data.getDes())) {
						t_list.add(data);
					}
				}
				OtherList domain = new OtherList();
				domain.setId("2");
				domain.setTp("tp");
				domain.setVal("val");
				domain.setDes("des");
				domain.setSort(2);
				domain.setCreateTime(new Date());
				jsonList.add(domain);
				set.add(other.getDes());
			}
		}
		return JSON.toJSONString(jsonList, SerializerFeature.WriteMapNullValue);
	}

}
